package arithmetic;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.junit.jupiter.api.Test;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

/**
 * @author jiangfeng
 * Created on 2020-03-23
 */
public class TestList {
    public static void main(String[] args) {
        //test();
        testSets();
    }

    /**
     * 测试 Lists.partition 是copy还是 原对象
     * <p>
     * 测试结果:原对象
     */
    public static void test() {
        List<TestClass> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            TestClass testClass = new TestClass(String.valueOf(i), String.valueOf(i), i);
            list.add(testClass);
        }
        List<List<TestClass>> partitionedList = Lists.partition(list, 3);
        System.out.println(partitionedList);
        for (TestClass testClasses : list) {
            testClasses.setC(2);
        }
        System.out.println(partitionedList);
    }

    @Test
    public static void testSets() {
        Set<Integer> set1 = Sets.newHashSet(1, 2, 4, 5, 6, 8);
        Set<Integer> set2 = Sets.newHashSet(2, 3, 4, 5, 6, 7, 9);

        //合集，并集   [1, 2, 4, 5, 6, 8, 3, 7, 9]
        Set<Integer> result1 = Sets.union(set1, set2);
        //交集          [2, 4, 5, 6]
        Set<Integer> result2 = Sets.intersection(set1, set2);
        //差集 1中有而2中没有的  [1, 8]
        Set<Integer> result3 = Sets.difference(set1, set2);
        //相对差集 1中有2中没有  2中有1中没有的 取出来做结果 [1, 8, 3, 7, 9]
        Set<Integer> result4 = Sets.symmetricDifference(set1, set2);

        System.out.println(result1);
        System.out.println(result2);
        System.out.println(result3);
        System.out.println(result4);

    }

    public static class TestClass {
        String a;
        String b;
        Integer c;

        @Override
        public String toString() {
            return "TestClass{" +
                    "a='" + a + '\'' +
                    ", b='" + b + '\'' +
                    ", c=" + c +
                    '}';
        }

        public String getA() {
            return a;
        }

        public void setA(String a) {
            this.a = a;
        }

        public String getB() {
            return b;
        }

        public void setB(String b) {
            this.b = b;
        }

        public Integer getC() {
            return c;
        }

        public void setC(Integer c) {
            this.c = c;
        }

        public TestClass(String a, String b, Integer c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }
    }
}
